home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / myPlatform ƒ / sMovPlatform.p < prev    next >
Encoding:
Text File  |  1994-07-26  |  2.6 KB  |  109 lines  |  [TEXT/PJMM]

  1. { Platform sprite, moveable version, not faceless }
  2.  
  3. unit sMovPlatForm;
  4.  
  5. interface
  6.  
  7.     uses
  8.         SAT, sPlatForm;
  9.  
  10.     var
  11.         platFace: FacePtr;
  12.  
  13.     procedure InitMovPlatForm;
  14.     procedure SetupMovPlatForm (me: SpritePtr);
  15.     procedure HandleMovPlatForm (me: SpritePtr);
  16.     procedure HitMovPlatForm (me, him: SpritePtr);
  17.  
  18. implementation
  19.  
  20.     procedure InitMovPlatForm;
  21.         var
  22.             i: integer;
  23.     begin
  24.         platFace := GetFace(138);
  25.     end;
  26.  
  27.     procedure SetupMovPlatForm (me: SpritePtr);
  28.         var
  29.             r: Rect;
  30.             pol: PolyHandle;
  31.     begin
  32.         me^.speed.v := -1 + Rand(2) * 2;
  33.         {me^.kind := -2; {Enemy kind}
  34.         me^.face := platFace;
  35.         SetRect(me^.hotRect, 0, 3, 60, 20);
  36.         me^.task := @HandleMovPlatform;
  37.         me^.hittask := @HitMovPlatform;
  38.     end;
  39.  
  40.     procedure HandleMovPlatForm (me: SpritePtr);
  41.     begin
  42.         me^.position.v := me^.position.v + me^.speed.v;
  43.         if me^.position.v < 40 then
  44.             me^.speed.v := 1;
  45.         if me^.position.v > gSAT.offSizeV - 32 then
  46.             me^.speed.v := -1;
  47.  
  48. {Move}
  49.         if me^.speed.v = 0 then
  50.             if me^.position.v > gSAT.offSizeV div 2 then
  51.                 me^.speed.v := -1
  52.             else
  53.                 me^.speed.v := 1;
  54.  
  55.         me^.layer := -me^.position.v;
  56.     end;
  57.  
  58.     procedure HitMovPlatForm;
  59.         var
  60.             mini, i, min: integer;
  61.             diff: array[1..4] of integer;
  62.     begin
  63.         if him^.Task <> @HandlePlatForm then {check for HandleMovPlatForm too?}
  64.             begin
  65.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
  66.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
  67.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
  68.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
  69.                 mini := 0;
  70.                 min := 10000;
  71.                 for i := 1 to 4 do
  72.                     if min > diff[i] then
  73.                         begin
  74.                             min := diff[i];
  75.                             mini := i;
  76.                         end;
  77.                 case mini of
  78.                     1: {floor}
  79.                         begin
  80.                             him^.position.v := him^.position.v - diff[1] + 2;
  81.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  82.                             if him^.speed.v > 0 then
  83.                                 him^.speed.v := 0;
  84.                         end;
  85.                     2: {cieling (sp?)}
  86.                         begin
  87.                             him^.position.v := him^.position.v + diff[2] + 1;
  88. {No signal here}
  89.                             if him^.speed.v < 0 then
  90.                                 him^.speed.v := -him^.speed.v;
  91.                         end;
  92.                     3: {left}
  93.                         begin
  94.                             him^.position.h := him^.position.h - diff[3] - 1;
  95.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  96.                             if him^.speed.h > 0 then
  97.                                 him^.speed.h := -him^.speed.h;
  98.                         end;
  99.                     4: {right}
  100.                         begin
  101.                             him^.position.h := him^.position.h + diff[4] + 1;
  102.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  103.                             if him^.speed.h < 0 then
  104.                                 him^.speed.h := -him^.speed.h;
  105.                         end;
  106.                 end;{case}
  107.             end; {if}
  108.     end; {HitMovPlatForm}
  109. end.{of unit}